<?php
/**
 * @package YARBB
 * @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * YARBB! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */
/** no direct access */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

// Display the smiley set 
require $yarbb_path.'/plugins/parser.php';
// Удаляем смайл?
if (isset($_POST['delete_smiley'])) {
	if (!$_POST['toremove']) {
		mosRedirect ($_SERVER['REQUEST_URI'], _Y_SMILNONDEL);
	}
	else {
		global $database;
		$toremove = stripslashes($_POST['toremove']);

		// Remove the selected smiley from the database
		$sql = ("DELETE FROM #__forum_smilies WHERE text = '$toremove'");
		$database->setQuery($sql);
		$database->Query($sql);
		mosRedirect ($_SERVER['REQUEST_URI'], _Y_SMILDEL);
	}
}
// If the "Submit Smiley" button was clicked
if (isset($_POST['submit_smiley'])) {
	// Make sure something something was entered
	if (trim($_POST['smiley_code']) == '')
		mosRedirect ($_SERVER['REQUEST_URI'], _Y_SMILECODNO);
	if (trim($_POST['smiley_image']) == '')
		mosRedirect ($_SERVER['REQUEST_URI'], _Y_SMILEIMGNO);
	$smiley_code = $_POST['smiley_code'];
	$smiley_image = $_POST['smiley_image'];
	// Добавляем новый смайл в бд
	$sql = ("INSERT INTO #__forum_smilies (id, image, text) VALUES('', '$smiley_image', '$smiley_code')");
	$database->setQuery($sql);
	$database->Query($sql);


	mosRedirect ($_SERVER['REQUEST_URI'], _Y_SMILEADD);
}
else	// If not, we show the "Show Smiley" form
{

	?>

<table class="adminheading">
	<tr>
		<th class="menus"> <span><?php echo _Y_MENEG_SMILE; ?></span> </th>
	</tr>
</table>
<form id="example" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
	<table width="100%" class="adminlist">
		<tr>
			<th colspan="3"> <?php echo _Y_SMILENEW; ?></th>
		</tr>
		<tr class="row0">
			<td width="10%"><?php echo _Y_SMILECODE; ?> </td>
			<td width="20%"><input type="text" name="smiley_code" size="25" tabindex="1" />
				<span><?php echo mosToolTip(_Y_SMILECODE_D); ?></span> </td>
			<td rowspan="3" align="right" valign="top"  class="message" ><?php echo _Y_SMILEDESC; ?></td>
		</tr>
		<tr class="row0">
			<td><?php echo _Y_SMILEIMG; ?></td>
			<td width="20%"><input type="text" name="smiley_image" size="25" tabindex="1" />
				<span><?php echo mosToolTip(_Y_SMILEIMG_D); ?></span></td>
		</tr>
		<tr class="row0">
			<td>&nbsp;</td>
			<td><input type="submit" name="submit_smiley" value="<?php echo _E_ADD; ?>" tabindex="2" />
			</td>
		</tr>
	</table>
</form>
<form id="adminForm" method="post" name="adminForm" action="index2.php?option=com_forum&amp;task=smilies&amp;delsmiley=yes">
	<table class="adminlist">
		<tr>
			<th colspan="4"> <?php echo _Y_SMILECURR; ?></th>
		</tr>
		<tr>
			<th width="5%"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th><?php echo _Y_SMILECODE; ?></th>
			<th><?php echo _Y_SMILEIMG; ?></th>
			<th><?php echo _IMAGE; ?></th>
			<th></th>
		</tr>
	<?php
	$num_smilies = count($smiley_text);
			for ($i = 0; $i < $num_smilies; ++$i) {
				// Is there a smiley at the current index?
				if (!isset($smiley_text[$i]))
					continue;
				$checked	= mosCommonHTML::CheckedOutProcessing($row,$i,$cur_text);
				echo "<tr class=\"row".$k."\" id=\"tr-el-".$row->id."\">";
				echo '<td  align="center">'.$checked.'</td><td>'.$smiley_text[$i].'</td>';
				// Save the current text and image
				$cur_img = $smiley_img[$i];
				$cur_text = $smiley_text[$i];
				echo "<td>".$cur_img."</td>";
				echo "<td><img src=\"".$yarbb_live."/images/smilies/".$cur_img."\"></td>";
				echo "<td><input type=\"hidden\" name=\"toremove\" value=\"$cur_text\">
		<input type=\"submit\" name=\"delete_smiley\" value=\"";
				echo _E_REMOVE;
				echo "\" tabindex=\"2\">
	</td>
	";

			}
			?>
		<tr class="row0">
			<td colspan="4"><?php echo _Y_SMILETOT; ?> <?php echo $num_smilies ?></td>
		</tr>
	</table>
</form>
	<?php
}